package com.learn.xueer.app.ext

import android.app.Activity
import android.widget.ProgressBar
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.customview.customView
import com.afollestad.materialdialogs.customview.getCustomView
import com.afollestad.materialdialogs.lifecycle.lifecycleOwner
import com.learn.xueer.R
import com.learn.xueer.app.util.SettingUtil

/**
 * @author : hgj
 * @date : 2020/6/28
 */

private var takeDialog: MaterialDialog? = null

fun AppCompatActivity.showDialogExt(take: () -> Unit, photo: () -> Unit) {
    if (!this.isFinishing) {
        if (takeDialog == null) {
            takeDialog = MaterialDialog(this)
                .cancelable(true)
                .cancelOnTouchOutside(false)
                .cornerRadius(12f)
                .customView(R.layout.layout_custom_take_photo_dialog_view)
                .lifecycleOwner(this)
            takeDialog?.getCustomView()?.run {
                this.findViewById<TextView>(R.id.take).setOnClickListener {
                    take()
                    dismissTakeExt()
                }
                this.findViewById<TextView>(R.id.photo).setOnClickListener {
                    photo()
                    dismissTakeExt()
                }
                this.findViewById<TextView>(R.id.cancel).setOnClickListener {
                    dismissTakeExt()
                }

            }
        }
        takeDialog?.show()
    }
}

fun Activity.dismissTakeExt() {
    takeDialog?.dismiss()
    takeDialog = null
}

fun Fragment.dismissTakeExt() {
    takeDialog?.dismiss()
    takeDialog = null
}
